package net.sf.rose.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import net.sf.rose.exception.SystemErrorCode;
import net.sf.rose.exception.SystemException;
import net.sf.rose.jdbc.service.SQLService;

import org.apache.log4j.Logger;

/**
 * 功能：配置文件读取
 * @author fengjian
 * @since 2013/10/15
 */
public class ConfigService {

	private static Logger logger = Logger.getLogger(ConfigService.class);

	/** 本地SQL语句文本信息类 */
	private Properties configs = new Properties();
	
	protected void initial(String fileName){
		InputStream in = SQLService.class.getClassLoader().getResourceAsStream(fileName);
		if (in != null) {
			try {
				configs.load(in);
				in.close();
			} catch (IOException e) {
				String message = "配置文件读取失败！";
				logger.error(message, e);
				throw new SystemException(message, SystemErrorCode.SQL_FILE_LOAD_ERROR);
			}
		}
	}

	/**
	 * 
	 */
	public String getString(String sqlKey){
		return configs.getProperty(sqlKey);
	}

}
